package com.yanqu.road.server.manger.activity.recycle;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.ActivityItemRecycleData;
import com.yanqu.road.entity.activity.springunionbanquet.config.SpringUnionBanquetConfig;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.springunionbanquet.SpringUnionBanquetMgr;

import java.util.ArrayList;
import java.util.List;

public class SpringBanquetRecycleStrategy extends AbstractItemRecycleStrategy {

    @Override
    public void markNeedRecycleItem() {
        ActivityInfo activityInfo = SpringUnionBanquetMgr.getActivityInfo();

        if (ActivityMgr.activityInShowTime(activityInfo)) {
            long recycleTime = activityInfo.getEndShowTime() * 1000L + gapTime;
            SpringUnionBanquetConfig config = SpringUnionBanquetMgr.getConfig();
            if (config != null) {
                List<String> paramList = new ArrayList<>();
                paramList.add(String.valueOf(config.getItemId1()));
                paramList.add("");
                paramList.add("");
                paramList.add(config.getActivityInfo().getActivityName());
                ActivityItemRecycleMgr.addRecycleItemData(config.getItemId1(), activityType, 1, recycleTime, paramList);

                paramList = new ArrayList<>();
                paramList.add(String.valueOf(config.getItemId2()));
                paramList.add("");
                paramList.add("");
                paramList.add(config.getActivityInfo().getActivityName());
                ActivityItemRecycleMgr.addRecycleItemData(config.getItemId2(), activityType, 1, recycleTime, paramList);

            }
        }
    }

    @Override
    protected void initActivityType() {
        activityType = eActivityType.SpringUnionBanquet.getValue();
    }

    @Override
    protected void doRecycle(long userId, ActivityItemRecycleData data) {
        if(data.getRecycleType() == 1){
            int itemId = data.getItemId();
            UserBagItem userBagItem = getUserBagItem(userId, itemId);
            if (userBagItem != null && userBagItem.getNum() > 0) {
                removeItem(userBagItem);
            }
        }
    }

    @Override
    public boolean isActivityRunning() {
        return false;
    }
}
